package com.yushixin.order.service.impl;

import com.yushixin.common.annotation.Read;
import com.yushixin.common.annotation.Write;
import com.yushixin.common.util.SnowflakeIdWorker;
import com.yushixin.order.model.Order;
import com.yushixin.order.repository.IOrderRepository;
import com.yushixin.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Read
public class OrderServiceImpl implements IOrderService {
    
    @Autowired
    private IOrderRepository orderRepository;
    
    @Override
    public List<Order> findAll() {
        return orderRepository.findAll(Sort.by("id"));
    }
    
    @Override
    @Write
    public void createOrder(Order order) {
        order.setId(SnowflakeIdWorker.generateId());
        orderRepository.save(order);
    }
}
